import { _decorator, log, Node, Tween, tween, UIOpacity, v3 } from 'cc';
import ViewAnimBase from './ViewAnimBase';
const { ccclass, property, menu } = _decorator;

@ccclass('ViewAnimScale')
@menu('ViewAnim/ViewAnimScale')
export default class ViewAnimScale extends ViewAnimBase {
    private _originScale: number = 0;


    initialize(): void {
        this._originScale = this.node.getScale().x;
    }

    private tween: Tween< Node >;

    runInAction( duration: number ): void {
        if( this.tween ) this.tween.stop();

        this.node.active = true;

        this.node.setScale( 0, 0, 0);


        this.tween = tween( this.node )
            .to( duration * 0.6, { scale: v3(1.15, 1.15, 1.15) })
            .to( duration * 0.4, { scale: v3(this._originScale, this._originScale, this._originScale)})
        .start();
    }

    runOutAction( duration: number ): void {
        if( this.tween ) this.tween.stop();
        
        this.tween = tween( this.node )
            .to( duration, {scale: v3( 0, 0, 0)})
            .call( () => this.node.active = false)
            .start();
    }
}


